# events for pygame
# import this module (pyg_sensor) and start getting events 
# of type pyg_sensor.SENSOR.
# The events support at least the attributes x,y,z, which 
# represent acceleration data of the respective axis, or
# anything else invented or altered by filters in Sensor.

# hack for dev
PATH = "/home/peter/Sensorstuff/PySensor"
import sys
sys.path.append(PATH)
# end hack for dev

import pygame
import Sensor

SENSOR = pygame.USEREVENT + 42
class EventSender(object):
    def __init__(self):
        self.sensor_receiver = Sensor.SensorReceiver()
        self.sensor_receiver.register(self.react)
        self.forwarding = True
    def react(self, dic):
        if pygame.display.get_init() and self.forwarding:
            event = pygame.event.Event(SENSOR, dic)
            pygame.event.post(event)
    def close(self):
        self.forwarding = False
        self.sensor_receiver.close_wait()

event_sender = EventSender()
def close():
    event_sender.close()
# pygame.register_quit(close)
# while this seems to work it crashes the interpreter at
# the end of the program. It appears to stop nicely without
# closing the receiving thread.
